

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=auto>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/favicon.png">
  <link rel="icon" href="/img/favicon.png">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="author" content="Han Qiu">
  <meta name="keywords" content="">
  
    <meta name="description" content="一、rem基础 rem（root em）是一个相对单位，类似与em，em是父元素字体大小，rem是html元素字体大小 比如，根元素（html）设置font-size&#x3D;12px，非根元素设置width: 2rem; 则换成px表示就是24px   rem的优点就是可以通过修改html里面的文字大小来改变页面中元素的大小，可以整体控制  二、媒体查询1、什么是媒体查询 媒体查询（Media Quer">
<meta property="og:type" content="article">
<meta property="og:title" content="rem适配布局">
<meta property="og:url" content="http://example.com/2022/02/14/rem%E9%80%82%E9%85%8D%E5%B8%83%E5%B1%80/index.html">
<meta property="og:site_name" content="寒秋の博客">
<meta property="og:description" content="一、rem基础 rem（root em）是一个相对单位，类似与em，em是父元素字体大小，rem是html元素字体大小 比如，根元素（html）设置font-size&#x3D;12px，非根元素设置width: 2rem; 则换成px表示就是24px   rem的优点就是可以通过修改html里面的文字大小来改变页面中元素的大小，可以整体控制  二、媒体查询1、什么是媒体查询 媒体查询（Media Quer">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://gitee.com/huqian025/my-images/raw/master/css/rem%E9%80%82%E9%85%8D%E5%B8%83%E5%B1%80/%E5%AA%92%E4%BD%93%E7%B1%BB%E5%9E%8B.png">
<meta property="og:image" content="https://gitee.com/huqian025/my-images/raw/master/css/rem%E9%80%82%E9%85%8D%E5%B8%83%E5%B1%80/%E5%AA%92%E4%BD%93%E7%89%B9%E6%80%A7.png">
<meta property="og:image" content="https://gitee.com/huqian025/my-images/raw/master/css/rem%E9%80%82%E9%85%8D%E5%B8%83%E5%B1%80/less%E5%8F%98%E9%87%8F.png">
<meta property="og:image" content="https://gitee.com/huqian025/my-images/raw/master/css/rem%E9%80%82%E9%85%8D%E5%B8%83%E5%B1%80/less%E5%B5%8C%E5%A5%97.png">
<meta property="og:image" content="https://gitee.com/huqian025/my-images/raw/master/css/rem%E9%80%82%E9%85%8D%E5%B8%83%E5%B1%80/less%E8%BF%90%E7%AE%97.png">
<meta property="og:image" content="https://gitee.com/huqian025/my-images/raw/master/css/rem%E9%80%82%E9%85%8D%E5%B8%83%E5%B1%80/rem%E9%80%82%E9%85%8D%E6%96%B9%E6%A1%88%E6%8A%80%E6%9C%AF%E4%BD%BF%E7%94%A8.png">
<meta property="og:image" content="https://gitee.com/huqian025/my-images/raw/master/css/rem%E9%80%82%E9%85%8D%E5%B8%83%E5%B1%80/%E8%AE%BE%E8%AE%A1%E7%A8%BF%E5%B8%B8%E8%A7%81%E5%B0%BA%E5%AF%B8%E5%AE%BD%E5%BA%A6.png">
<meta property="og:image" content="https://gitee.com/huqian025/my-images/raw/master/css/rem%E9%80%82%E9%85%8D%E5%B8%83%E5%B1%80/%E5%8A%A8%E6%80%81%E8%AE%BE%E7%BD%AEhtml%E6%A0%87%E7%AD%BEfont-size.png">
<meta property="og:image" content="https://gitee.com/huqian025/my-images/raw/master/css/rem%E9%80%82%E9%85%8D%E5%B8%83%E5%B1%80/flexible.js+rem.png">
<meta property="article:published_time" content="2022-02-14T03:35:20.000Z">
<meta property="article:modified_time" content="2022-02-15T03:47:50.104Z">
<meta property="article:author" content="Han Qiu">
<meta property="article:tag" content="rem">
<meta property="article:tag" content="媒体查询">
<meta property="article:tag" content="less">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:image" content="https://gitee.com/huqian025/my-images/raw/master/css/rem%E9%80%82%E9%85%8D%E5%B8%83%E5%B1%80/%E5%AA%92%E4%BD%93%E7%B1%BB%E5%9E%8B.png">
  
  
  <title>rem适配布局 - 寒秋の博客</title>

  <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4/dist/css/bootstrap.min.css" />


  <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/github-markdown-css@4/github-markdown.min.css" />
  <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/hint.css@2/hint.min.css" />

  
    
    
      
      <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/highlight.js@10/styles/github-gist.min.css" />
    
  

  
    <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3/dist/jquery.fancybox.min.css" />
  


<!-- 主题依赖的图标库，不要自行修改 -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_ba1fz6golrf.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_lbnruvf0jn.css">


<link  rel="stylesheet" href="/css/main.css" />

<!-- 自定义样式保持在最底部 -->


  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    var CONFIG = {"hostname":"example.com","root":"/","version":"1.8.14","typing":{"enable":true,"typeSpeed":70,"cursorChar":"_","loop":false},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"right","visible":"hover","icon":""},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"copy_btn":true,"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":0},"lazyload":{"enable":true,"loading_img":"/img/loading.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":false,"baidu":null,"google":null,"gtag":null,"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":null,"app_key":null,"server_url":null,"path":"window.location.pathname","ignore_local":false}},"search_path":"/local-search.xml"};
  </script>
  <script  src="/js/utils.js" ></script>
  <script  src="/js/color-schema.js" ></script>
<meta name="generator" content="Hexo 6.0.0"></head>


<body>
  <header style="height: 70vh;">
    <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand" href="/">
      <strong>blogs</strong>
    </a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                <i class="iconfont icon-home-fill"></i>
                首页
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/">
                <i class="iconfont icon-archive-fill"></i>
                归档
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/categories/">
                <i class="iconfont icon-category-fill"></i>
                分类
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/tags/">
                <i class="iconfont icon-tags-fill"></i>
                标签
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                <i class="iconfont icon-user-fill"></i>
                关于
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" href="javascript:;" data-toggle="modal" data-target="#modalSearch" aria-label="Search">
              &nbsp;<i class="iconfont icon-search"></i>&nbsp;
            </a>
          </li>
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self" href="javascript:;" aria-label="Color Toggle">&nbsp;<i
                class="iconfont icon-dark" id="color-toggle-icon"></i>&nbsp;</a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

    <div class="banner" id="banner" parallax=true
         style="background: url('/img/default.png') no-repeat center center;
           background-size: cover;">
      <div class="full-bg-img">
        <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
          <div class="page-header text-center fade-in-up">
            <span class="h2" id="subtitle" title="rem适配布局">
              
            </span>

            
              <div class="mt-3">
  
  
    <span class="post-meta">
      <i class="iconfont icon-date-fill" aria-hidden="true"></i>
      <time datetime="2022-02-14 11:35" pubdate>
        2022年2月14日 中午
      </time>
    </span>
  
</div>

<div class="mt-1">
  
    <span class="post-meta mr-2">
      <i class="iconfont icon-chart"></i>
      2.4k 字
    </span>
  

  
    <span class="post-meta mr-2">
      <i class="iconfont icon-clock-fill"></i>
      
      
      20 分钟
    </span>
  

  
  
</div>

            
          </div>

          
        </div>
      </div>
    </div>
  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="d-none d-lg-block col-lg-2"></div>
    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div class="py-5" id="board">
          <article class="post-content mx-auto">
            <!-- SEO header -->
            <h1 style="display: none">rem适配布局</h1>
            
            <div class="markdown-body">
              <h3 id="一、rem基础"><a href="#一、rem基础" class="headerlink" title="一、rem基础"></a>一、rem基础</h3><ul>
<li>rem（root em）是一个相对单位，类似与em，em是父元素字体大小，rem是html元素字体大小<ul>
<li>比如，根元素（html）设置font-size=12px，非根元素设置width: 2rem; 则换成px表示就是24px</li>
</ul>
</li>
<li>rem的优点就是可以通过修改html里面的文字大小来改变页面中元素的大小，可以整体控制</li>
</ul>
<h3 id="二、媒体查询"><a href="#二、媒体查询" class="headerlink" title="二、媒体查询"></a>二、媒体查询</h3><h4 id="1、什么是媒体查询"><a href="#1、什么是媒体查询" class="headerlink" title="1、什么是媒体查询"></a>1、什么是媒体查询</h4><ul>
<li>媒体查询（Media Query）是css3新语法，使用@media查询，可以针对不同的媒体类型定义不同的样式</li>
<li><code>@media可以针对不同的屏幕尺寸设置不同的样式</code></li>
<li>当你重置浏览器大小的过程中，页面也会根据浏览器的宽度和高度重新渲染页面</li>
</ul>
<h4 id="2、语法规范"><a href="#2、语法规范" class="headerlink" title="2、语法规范"></a>2、语法规范</h4><figure class="highlight css"><table><tr><td class="gutter"><div class="code-wrapper"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></div></td><td class="code"><pre><code class="hljs css"><span class="hljs-keyword">@media</span> mediatype <span class="hljs-keyword">and</span>|<span class="hljs-keyword">not</span>|<span class="hljs-keyword">only</span> (media feature) &#123;<br>    css-<span class="hljs-selector-tag">code</span>;<br>&#125;<br></code></pre></td></tr></table></figure>

<ul>
<li>用@media开头，注意@符号</li>
<li>mediatype 媒体类型</li>
</ul>
<p><img src="https://gitee.com/huqian025/my-images/raw/master/css/rem%E9%80%82%E9%85%8D%E5%B8%83%E5%B1%80/%E5%AA%92%E4%BD%93%E7%B1%BB%E5%9E%8B.png" srcset="/img/loading.gif" lazyload alt="媒体类型"></p>
<ul>
<li>关键字 and not only</li>
<li>media feature 媒体特性，必须有小括号包含</li>
</ul>
<p><img src="https://gitee.com/huqian025/my-images/raw/master/css/rem%E9%80%82%E9%85%8D%E5%B8%83%E5%B1%80/%E5%AA%92%E4%BD%93%E7%89%B9%E6%80%A7.png" srcset="/img/loading.gif" lazyload alt="媒体特性"></p>
<h4 id="3、媒体查询-rem实现元素动态大小变化"><a href="#3、媒体查询-rem实现元素动态大小变化" class="headerlink" title="3、媒体查询+rem实现元素动态大小变化"></a>3、媒体查询+rem实现元素动态大小变化</h4><ul>
<li>rem单位是跟着html走的，有了rem页面元素可以设置不同大小尺寸</li>
<li>媒体查询可以根据不同设备宽度来修改样式</li>
<li>媒体查询+rem就可以实现不同设备宽度，页面元素大小的动态变化<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><code class="hljs css"><span class="hljs-keyword">@media</span> screen <span class="hljs-keyword">and</span> (<span class="hljs-attribute">min-width</span>: <span class="hljs-number">320px</span>) &#123;<br>    <span class="hljs-selector-tag">html</span> &#123;<br>        <span class="hljs-attribute">font-size</span>: <span class="hljs-number">50px</span>;<br>    &#125;<br>&#125;<br><br><span class="hljs-keyword">@media</span> screen <span class="hljs-keyword">and</span> (<span class="hljs-attribute">min-width</span>: <span class="hljs-number">640px</span>) &#123;<br>    <span class="hljs-selector-tag">html</span> &#123;<br>        <span class="hljs-attribute">font-size</span>: <span class="hljs-number">100px</span>;<br>    &#125;<br>&#125;<br><br><span class="hljs-selector-class">.top</span> &#123;<br>    <span class="hljs-attribute">height</span>: <span class="hljs-number">1rem</span>;<br>    <span class="hljs-attribute">font-size</span>: .<span class="hljs-number">5rem</span>;<br>    <span class="hljs-attribute">background-color</span>: green;<br>    <span class="hljs-attribute">color</span>: <span class="hljs-number">#fff</span>;<br>    <span class="hljs-attribute">text-align</span>: center;<br>    <span class="hljs-attribute">line-height</span>: <span class="hljs-number">1rem</span>;<br>&#125;<br></code></pre></td></tr></table></figure></li>
</ul>
<h4 id="4、引入资源"><a href="#4、引入资源" class="headerlink" title="4、引入资源"></a>4、引入资源</h4><ul>
<li>当样式比较繁多的时候，我们可以针对不同的媒体使用不同的stylesheets（样式表）</li>
<li>原理：在link中判断设备的尺寸，然后引入不同的css文件<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><code class="hljs html"><span class="hljs-comment">&lt;!-- 建议媒体查询从小到大 --&gt;</span><br><span class="hljs-comment">&lt;!-- 针对不同的屏幕尺寸，调用不同的css文件 --&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">link</span> <span class="hljs-attr">rel</span>=<span class="hljs-string">&quot;stylesheet&quot;</span> <span class="hljs-attr">href</span>=<span class="hljs-string">&quot;style320.css&quot;</span> <span class="hljs-attr">media</span>=<span class="hljs-string">&quot;screen and (min-width: 320px)&quot;</span>&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">link</span> <span class="hljs-attr">rel</span>=<span class="hljs-string">&quot;stylesheet&quot;</span> <span class="hljs-attr">href</span>=<span class="hljs-string">&quot;style640.css&quot;</span> <span class="hljs-attr">media</span>=<span class="hljs-string">&quot;screen and (min-width: 640px)&quot;</span>&gt;</span><br></code></pre></td></tr></table></figure></li>
</ul>
<h3 id="三、less基础"><a href="#三、less基础" class="headerlink" title="三、less基础"></a>三、less基础</h3><h4 id="1、css弊端"><a href="#1、css弊端" class="headerlink" title="1、css弊端"></a>1、css弊端</h4><p>css是一门非程序式语言，没有变量、函数、SCOPE（作用域）等概念</p>
<ul>
<li>css需要书写大量看似没有逻辑的代码，css冗余度是比较高的</li>
<li>不方便维护及扩展，不利于复用</li>
<li>css没有很好的计算能力</li>
<li>非前端开发工程师来讲，往往因为缺少css编写经验而很难写出组织良好且易于维护的css代码项目</li>
</ul>
<h4 id="2、less介绍"><a href="#2、less介绍" class="headerlink" title="2、less介绍"></a>2、less介绍</h4><p>Less（Leaner Style Sheets）是一门css预处理语言，它扩展了css的动态特性</p>
<h4 id="3、less使用"><a href="#3、less使用" class="headerlink" title="3、less使用"></a>3、less使用</h4><p>首先新建一个后缀名为.less的文件，在这个less文件里面书写less语句</p>
<h5 id="3-1、less变量"><a href="#3-1、less变量" class="headerlink" title="3.1、less变量"></a>3.1、less变量</h5><p><code>@变量名: 变量值;</code></p>
<p>变量命名规范：</p>
<ul>
<li><p>必须有@为前缀</p>
</li>
<li><p>不能包含特殊字符</p>
</li>
<li><p>不能以数字开头</p>
</li>
<li><p>大小写敏感</p>
</li>
</ul>
<p><img src="https://gitee.com/huqian025/my-images/raw/master/css/rem%E9%80%82%E9%85%8D%E5%B8%83%E5%B1%80/less%E5%8F%98%E9%87%8F.png" srcset="/img/loading.gif" lazyload alt="less变量"></p>
<h5 id="3-2、less编译"><a href="#3-2、less编译" class="headerlink" title="3.2、less编译"></a>3.2、less编译</h5><ul>
<li>方法一：vsCode安装easy less插件，保存less会自动编译为同目录下同名css</li>
<li>方法二：通过npm安装less（<code>全局：npm install less -g，局部：npm install less --save-dev</code> ），编译<code>lessc less文件名 css文件名</code>（例如：<code>lessc bootstrap.less bootstrap.css</code>）</li>
</ul>
<h5 id="3-3、less嵌套"><a href="#3-3、less嵌套" class="headerlink" title="3.3、less嵌套"></a>3.3、less嵌套</h5><ul>
<li>子元素的样式直接写在父元素里面</li>
<li>如果有伪类、交集选择器、伪元素选择器，内层选择器的前面需要加&amp;</li>
<li>内层选择器的前面没有加&amp;符号，则它被解析为父选择器的后代</li>
</ul>
<p><img src="https://gitee.com/huqian025/my-images/raw/master/css/rem%E9%80%82%E9%85%8D%E5%B8%83%E5%B1%80/less%E5%B5%8C%E5%A5%97.png" srcset="/img/loading.gif" lazyload alt="less嵌套"></p>
<h5 id="3-4、less运算"><a href="#3-4、less运算" class="headerlink" title="3.4、less运算"></a>3.4、less运算</h5><p>任何数字、颜色或者变量都可以参与运算，less提供了加（+）、减（-）、乘（*）、除（/）算术运算</p>
<p><img src="https://gitee.com/huqian025/my-images/raw/master/css/rem%E9%80%82%E9%85%8D%E5%B8%83%E5%B1%80/less%E8%BF%90%E7%AE%97.png" srcset="/img/loading.gif" lazyload alt="less运算"></p>
<p><strong>注意：</strong></p>
<ol>
<li>运算符的左右两侧必须敲一个空格隔开</li>
<li>两个数参与运算，如果只有一个数有单位，则最后的结果就以这个单位为准</li>
<li>两个数参与运算，如果2个数都有单位，而且它们的单位不一样，最后的结果以第一个单位为准</li>
</ol>
<h3 id="四、rem适配方案"><a href="#四、rem适配方案" class="headerlink" title="四、rem适配方案"></a>四、rem适配方案</h3><h4 id="1、rem实际开发适配方案"><a href="#1、rem实际开发适配方案" class="headerlink" title="1、rem实际开发适配方案"></a>1、rem实际开发适配方案</h4><ol>
<li>按照设计稿与设备宽度的比例，动态计算并设置html根标签的font-size大小（媒体查询）</li>
<li>css中，设计稿元素的宽、高、相对位置等取值，按照同等比例换算成rem为单位的值</li>
</ol>
<h4 id="2、rem适配方案技术使用（市场主流）"><a href="#2、rem适配方案技术使用（市场主流）" class="headerlink" title="2、rem适配方案技术使用（市场主流）"></a>2、rem适配方案技术使用（市场主流）</h4><p><img src="https://gitee.com/huqian025/my-images/raw/master/css/rem%E9%80%82%E9%85%8D%E5%B8%83%E5%B1%80/rem%E9%80%82%E9%85%8D%E6%96%B9%E6%A1%88%E6%8A%80%E6%9C%AF%E4%BD%BF%E7%94%A8.png" srcset="/img/loading.gif" lazyload alt="rem适配方案技术使用"></p>
<h4 id="3、rem适配方案1（rem-媒体查询-less）"><a href="#3、rem适配方案1（rem-媒体查询-less）" class="headerlink" title="3、rem适配方案1（rem+媒体查询+less）"></a>3、rem适配方案1（rem+媒体查询+less）</h4><h5 id="3-1、设计稿常见尺寸宽度"><a href="#3-1、设计稿常见尺寸宽度" class="headerlink" title="3.1、设计稿常见尺寸宽度"></a>3.1、设计稿常见尺寸宽度</h5><p><img src="https://gitee.com/huqian025/my-images/raw/master/css/rem%E9%80%82%E9%85%8D%E5%B8%83%E5%B1%80/%E8%AE%BE%E8%AE%A1%E7%A8%BF%E5%B8%B8%E8%A7%81%E5%B0%BA%E5%AF%B8%E5%AE%BD%E5%BA%A6.png" srcset="/img/loading.gif" lazyload alt="设计稿常见尺寸宽度"></p>
<h5 id="3-2、动态设置html标签font-size大小"><a href="#3-2、动态设置html标签font-size大小" class="headerlink" title="3.2、动态设置html标签font-size大小"></a>3.2、动态设置html标签font-size大小</h5><p><img src="https://gitee.com/huqian025/my-images/raw/master/css/rem%E9%80%82%E9%85%8D%E5%B8%83%E5%B1%80/%E5%8A%A8%E6%80%81%E8%AE%BE%E7%BD%AEhtml%E6%A0%87%E7%AD%BEfont-size.png" srcset="/img/loading.gif" lazyload alt="动态设置html标签font-size"></p>
<h5 id="3-3、元素大小取值方法"><a href="#3-3、元素大小取值方法" class="headerlink" title="3.3、元素大小取值方法"></a>3.3、元素大小取值方法</h5><ul>
<li>最后的公式：页面元素的rem值=页面元素值（px）/（屏幕宽度 / 划分的份数）</li>
<li>屏幕宽度 / 划分的份数，就是html的font-size大小，页面元素的rem值=页面元素值（px）/ html的font-size字体大小</li>
</ul>
<h4 id="4、rem适配方案2（flexible-js-rem）"><a href="#4、rem适配方案2（flexible-js-rem）" class="headerlink" title="4、rem适配方案2（flexible.js+rem）"></a>4、rem适配方案2（flexible.js+rem）</h4><p><img src="https://gitee.com/huqian025/my-images/raw/master/css/rem%E9%80%82%E9%85%8D%E5%B8%83%E5%B1%80/flexible.js+rem.png" srcset="/img/loading.gif" lazyload alt="flexible.js+rem"></p>
<p>vsCode px转换rem插件（cssrem）</p>
<ul>
<li>默认html的font-size为16px</li>
<li>在setting.json中添加<code>&quot;cssrem.rootFontSize&quot;: 75</code>，将font-size改为75px，重启vscode</li>
</ul>

            </div>
            <hr>
            <div>
              <div class="post-metas mb-3">
                
                  <div class="post-meta mr-3">
                    <i class="iconfont icon-category"></i>
                    
                      <a class="hover-with-bg" href="/categories/css/">css</a>
                    
                  </div>
                
                
                  <div class="post-meta">
                    <i class="iconfont icon-tags"></i>
                    
                      <a class="hover-with-bg" href="/tags/rem/">rem</a>
                    
                      <a class="hover-with-bg" href="/tags/%E5%AA%92%E4%BD%93%E6%9F%A5%E8%AF%A2/">媒体查询</a>
                    
                      <a class="hover-with-bg" href="/tags/less/">less</a>
                    
                  </div>
                
              </div>
              
                <p class="note note-warning">
                  
                    本博客所有文章除特别声明外，均采用 <a target="_blank" href="https://creativecommons.org/licenses/by-sa/4.0/deed.zh" rel="nofollow noopener noopener">CC BY-SA 4.0 协议</a> ，转载请注明出处！
                  
                </p>
              
              
                <div class="post-prevnext">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/2022/02/14/bootstrap%E5%93%8D%E5%BA%94%E5%BC%8F%E5%B8%83%E5%B1%80/">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">bootstrap响应式布局</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/2022/02/14/%E7%A7%BB%E5%8A%A8%E7%AB%AF%E5%B8%83%E5%B1%80%E7%AE%80%E4%BB%8B/">
                        <span class="hidden-mobile">移动端布局简介</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
          </article>
        </div>
      </div>
    </div>
    
      <div class="d-none d-lg-block col-lg-2 toc-container" id="toc-ctn">
        <div id="toc">
  <p class="toc-header"><i class="iconfont icon-list"></i>&nbsp;目录</p>
  <div class="toc-body" id="toc-body"></div>
</div>

      </div>
    
  </div>
</div>

<!-- Custom -->


    

    
      <a id="scroll-top-button" aria-label="TOP" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v"
                 for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>
    

    
  </main>

  <footer class="text-center mt-5 py-3">
  <div class="footer-content">
     <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>Hexo</span></a> <i class="iconfont icon-love"></i> <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener"><span>Fluid</span></a> 
  </div>
  

  

  
</footer>


  <!-- SCRIPTS -->
  
  <script  src="https://cdn.jsdelivr.net/npm/nprogress@0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/nprogress@0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://cdn.jsdelivr.net/npm/jquery@3/dist/jquery.min.js" ></script>
<script  src="https://cdn.jsdelivr.net/npm/bootstrap@4/dist/js/bootstrap.min.js" ></script>
<script  src="/js/events.js" ></script>
<script  src="/js/plugins.js" ></script>

<!-- Plugins -->


  <script  src="/js/local-search.js" ></script>



  
    <script  src="/js/img-lazyload.js" ></script>
  



  



  
    <script  src="https://cdn.jsdelivr.net/npm/tocbot@4/dist/tocbot.min.js" ></script>
  
  
    <script  src="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3/dist/jquery.fancybox.min.js" ></script>
  
  
    <script  src="https://cdn.jsdelivr.net/npm/anchor-js@4/anchor.min.js" ></script>
  
  
    <script defer src="https://cdn.jsdelivr.net/npm/clipboard@2/dist/clipboard.min.js" ></script>
  






  <script  src="https://cdn.jsdelivr.net/npm/typed.js@2/lib/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var title = document.getElementById('subtitle').title;
      
        typing(title);
      
    })(window, document);
  </script>















<!-- 主题的启动项 保持在最底部 -->
<script  src="/js/boot.js" ></script>


</body>
</html>
